package br.com.cast.syscast.municipio.paginas;

import org.apache.wicket.Component;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.html.form.DropDownChoice;

import br.com.cast.syscast.models.Municipio;
import br.com.cast.syscast.models.Uf;
import br.com.cast.syscast.services.IUfService;

public class BuscaUfPorPaisBehavior extends Behavior {
	
	private IUfService ufService;

	public BuscaUfPorPaisBehavior(IUfService ufService) {
		this.ufService = ufService;
	}

	@Override
	public void beforeRender(Component component) {

		FormMunicipio form = (FormMunicipio) 
				component.getParent();
		
		Municipio m = form.getModelObject();
		
		if (m.getId() != null) {//flluxo de alteração
			
			DropDownChoice<Uf> dropDown = 
					(DropDownChoice<Uf>)component;
			
			dropDown.setChoices(
				ufService.consultaPorPais(
						m.getUf().getPais()));
		}
		
	}
		
}
